<?php
namespace App\Repository;

use App\Model\Level;

class LevelRepository extends \HyperfStore\Repository
{
    // 放入模型
    public function build()
    {
        return new Level;
    }
    
    // 判断等级变动
    public function is(UserRepository $user)
    {
        return $user->level_id <> $this->model->id;
    }
    
    // 补贴税收
    public function fullTax($money)
    {
        return bcmul($money, $this->model->full_tax / 100, 2);
    }
    
    // 直推奖比例
    public function userPrize($money)
    {
        return bcmul($money, $this->model->user_prize / 100, 2);
    }
    
    // 团队奖（差值）
    public function userAllPrize($money, $up)
    {
        // 算出差值比例
        $now = $this->model->user_all_prize - $up;
        
        if($now > 0)
        {
            return [bcmul($money, $now / 100, 2), $this->model->user_all_prize];
        }
    }
    
    // 判断是否需要复投
    public function moneyPay(UserRepository $user)
    {
        return ($user->money_full_all / $user->money_all) >= $this->model->money_pay;
    }
    
    // 充值优惠使用比例
    public function discountMake($money, $discount)
    {
        return bcmul($money, $this->model->discount_make / 100, 2) >= $discount;
    }
    
    // 补贴支付比例
    public function fullPay($money, $full)
    {
        return bcmul($money, $this->model->full_pay / 100, 2) >= $full;
    }
    
    // 补贴转帐开启
    public function fullTransfer()
    {
        return $this->model->full_transfer_on;
    }
    
    // 补贴转帐税
    public function fullTransferMoney($money)
    {
        return bcmul($money, $this->model->full_transfer / 100, 2);
    }
    
    // 优惠转帐开启
    public function discountTransfer()
    {
        return $this->model->discount_transfer_on;
    }
    
    // 优惠转帐税
    public function discountTransferMoney($money)
    {
        return bcmul($money, $this->model->discount_transfer / 100, 2);
    }
    
    
    // 补贴转优惠是否开启
    public function fullDiscount()
    {
        return $this->model->full_discount_on;
    }
    
    // 补贴转优惠税
    public function fullDiscountMoney($money)
    {
        return bcmul($money, $this->model->full_discount / 100, 2);
    }
    
    // 分红转补贴
    public function walletFull($money)
    {
        return bcmul($money, $this->model->wallet_full / 100, 2);
    }
    
    // 店铺考核
    public function shopMoney($money)
    {
        return $money >= $this->model->shop_money;
    }
    
    // 店铺比例
    public function shopPrize($money)
    {
        return bcmul($money, $this->model->shop_prize / 100, 2);
    }
    
    // 店铺上级比例
    public function shopShopPrize($money)
    {
        return bcmul($money, $this->model->shop_shop_prize / 100, 2);
    }
}